package com.tju.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tju.Result;
import com.tju.eduservice.entity.EduCourse;
import com.tju.eduservice.entity.EduTeacher;
import com.tju.eduservice.service.EduCourseService;
import com.tju.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherFront")
public class TeacherFrontController {
    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    //分页查询讲师
    @PostMapping("getTeacherList/{page}/{limit}")
    public Result getTeacherList(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> pageTeacher = new Page<>(page,limit);
        Map<String,Object> map = teacherService.getTeacherList(pageTeacher);

        return Result.ok().data(map);

    }
    //根据讲师id查询讲师信息  查询所讲的课程信息
    @GetMapping("getTeacherInfo/{teacherId}")
    public Result getTeacherInfo(@PathVariable long teacherId){
        //讲师信息
        EduTeacher teacher = teacherService.getById(teacherId);
        //课程信息
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);
        return Result.ok().data("teacher",teacher).data("courseList",courseList);

    }
}
